package br.com.threads;

class Calculando implements Runnable{
	int total;
	public void run(){
		synchronized (this) {
			for(int i = 0; i < 10; i++){
				total += i;
				notifyAll();
			}
		}		
	}
}
class Lendo implements Runnable{
	Calculando c;
	public Lendo(Calculando c){
		this.c = c;
	}
	public void run(){
		synchronized (c) {
			System.out.println("Calculando...: ");
			try{
				c.wait();
			}catch(InterruptedException e){
				e.getCause();
			}
		}
		System.err.println("Total do Calculo: " + c.total);
	}
}

public class Programa35 {
	public static void main(String[] args)  {
		Calculando c = new Calculando();
		Lendo l = new Lendo(c);
		new Thread(l).start();//chama o metodo run() de Lendo
		new Thread(l).start();//chama o metodo run() de Lendo
		new Thread(l).start();//chama o metodo run() de Lendo
		new Thread(c).start();//chama o metodo run() de Calculando que contem
		//uma chamada notifyAll()
		//new Thread(l).run();
		
	}
}
